<!--
 * @Descripttion: 
 * @Author: xiaodong
 * @Date: 2020-11-16 18:47:28
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
  </head>
  <body>
    <img class="imga" id="iii" width="200" height="120" src="./dog.jpeg" />
    index
    <script>
      function handlePerf() {
        const performance = window.performance;
        if (!performance || "object" !== typeof performance) {
          // 当前浏览器不支持
          console.log("你的浏览器不支持 performance 接口");
          return;
        }
        console.log(Performance);
        let data = {
            dns: 0, // DNS查询 domainLookupEnd - domainLookupStart
            tcp: 0, // TCP链接
            ssl: 0, // SSL建连
            ttfb: 0, // 请求响应
            trans: 0,
            dom: 0,
            res: 0,
            firstbyte: 0,
            fpt: 0,
            tti: 0,
            ready: 0,
            load: 0, // domready时间
          },
          timing = performance.timing || {},
          now = Date.now(),
          type = 1;
        console.log(timing);
        let stateCheck = setInterval(() => {
          if (timing.loadEventEnd) {
            clearInterval(stateCheck);

            // 根据PerformanceNavigationTiming计算更准确
            if ("function" == typeof window.PerformanceNavigationTiming) {
              var c = performance.getEntriesByType("navigation")[0];
              c && ((timing = c), (type = 2));
            }

            // 计算data
            each(
              {
                dns: [3, 2],
                tcp: [5, 4],
                ssl: [5, 17],
                ttfb: [7, 6],
                trans: [8, 7],
                dom: [10, 8],
                res: [14, 12],
                firstbyte: [7, 2],
                fpt: [8, 1],
                tti: [10, 1],
                ready: [12, 1],
                load: [14, 1],
              },
              function (e, t) {
                var r = timing[TIMING_KEYS[e[1]]],
                  o = timing[TIMING_KEYS[e[0]]];
                var c = Math.round(o - r);
                if (2 === type || (r !== undefined && o !== undefined)) {
                  if (t === "dom") {
                    var c = Math.round(o - r);
                  }
                  c >= 0 && c < 36e5 && (data[t] = c);
                }
              }
            );

            var u = window.navigator.connection,
              f = performance.navigation || { type: undefined };
            data.ct = u ? u.effectiveType || u.type : "";
            var l = u
              ? u.downlink || u.downlinkMax || u.bandwidth || null
              : null;
            if (
              ((l = l > 999 ? 999 : l) && (data.bandwidth = l),
              (data.navtype = 1 === f.type ? "Reload" : "Other"),
              1 === type &&
                timing[TIMING_KEYS[16]] > 0 &&
                timing[TIMING_KEYS[1]] > 0)
            ) {
              var h = timing[TIMING_KEYS[16]] - timing[TIMING_KEYS[1]];
              h >= 0 && h < 36e5 && (data.fpt = h);
            }
            1 === type && timing[TIMING_KEYS[1]] > 0
              ? (data.begin = timing[TIMING_KEYS[1]])
              : 2 === type && data.load > 0
              ? (data.begin = now - data.load)
              : (data.begin = now);
            let commonMsg = getCommonMsg();
            let msg = {
              ...commonMsg,
              t: "perf",
              ...data,
            };
            report(msg);
          }
        }, 50);
      }
      handlePerf();
    </script>
    <script src="./a.js"></script>
    <!-- <script src='./b.js'></script> -->
    <script>
      // console.log(b)
      function A() {
        B();
      }

      function B() {
        C();
      }

      function C() {
        console.log(c);
      }

      // A()

      // setTimeout(()=> {
      //   console.log(a)
      // },1000)
      //     function foo()
      // {
      // return Promise.reject('Hello!');
      // }

      //     var r = foo();

      //     setTimeout(() =>
      //     {
      //     r.catch(e =>{});
      //     }, 1000);
    </script>
    <!-- <a href='#a'>a</a> -->
    <button id="#btn" onclick="C()">aaa</button>
    <input class="name" />
    <textarea class="ta"></textarea>

    <script>
      fetch("http://localhost:5000/example/zan1");

      function C() {
        location.href = "#a";
        // let stateObj = {
        //   foo: "bar",
        //   };

        //   history.pushState(stateObj, "page 2", "bar.html");
        // console.log('a', 'b')
        // $.ajax({
        //   url: 'http://localhost:5000/example/zan'
        // });
        // $.ajax({
        //   type: 'POST',
        //   contentType: 'application/json',
        //   url: 'http://sitm.igola.com/web-gateway/api-data-service/data/find-hot',
        //   data: JSON.stringify({"lang":"ZH","timestamp":1569225444068}),
        //   dataType: 'json'
        // });
        // $.post('http://sitm.igola.com/web-gateway/api-data-service/data/find-hot',{"lang":"ZH","timestamp":1569225444068});
        // __bb.msg('A::a');
        // __bb.sum('A::b');
        // __bb.sum('A::c');
        // __bb.sum('B::a');
        // __bb.sum('B::b');
        // __bb.sum('B::c');
      }
    </script>
    <script></script>
  </body>
</html>
